<template>
	<view class="relative full-screen">
		<view class="page-bg" style="z-index:0;position:absolute;left:0;right:0;top:0;height:396px;background-image:radial-gradient(circle at left top, #D8230A26 50%, transparent 50%);background-size:396px 396px;background-repeat:no-repeat;filter:blur(50px);"></view>
		<uni-nav-bar ref="navBar" fixed statusBar :border="false" backgroundColor="white" @clickLeft="goBack">
			<template v-slot:left>
				<image class="size-32" src="@/static/svg/icon-back.svg" />
			</template>
			<view class="flex center w-full fs-16 text-black text-color-regular">复制已有活动</view>
		</uni-nav-bar>
		<z-paging ref="paging" :fixed="false" :paging-style="{height: `calc(100vh - ${navBarHeight || 0}px)`}"  v-model="dataList" @query="queryList">
			<template v-slot:top>
				<view class="bg-white">
					<search-bar v-model="queryParams.activeTitle" @search="onSearch" @clean="onClean" placeholder="搜索活动标题"></search-bar>
				</view>
			</template>
			<view v-for="(item, i) in dataList" :key="i" class="uni-bg-color px-16 pt-12">
				<ActivityItem :data="item" />
			</view>
		</z-paging>
	</view>
</template>

<script setup name="MyActivity">
	import { onBackPress, onLoad,onShow } from '@dcloudio/uni-app'
	import { onMounted, ref, unref, computed, onBeforeUnmount } from 'vue'
	import { getMyActiveApi } from '@/api/business.js'
	import ActivityItem from './components/ActivityItem.vue'
	
	const goBack = () => {
		uni.navigateBack()
	}
	const from = ref('')
	
	onBeforeUnmount(() => {
	})
	
	const navBar = ref(null)
	const navBarHeight = computed(() => {
		const statusBarHeight = uni.getWindowInfo().statusBarHeight
		const navigationBarHeight = statusBarHeight + (navBar.value && navBar.value.height || 0)
		return navigationBarHeight
	})
	const firstInfo = ref(true)
	
	const dataList = ref([])
	const paging = ref(null)
	const queryParams = ref({
		activeTitle: '',
		activeState: '', // 活动状态（1-未发布，2-未开始，3-进行中，4-已结束）
		pageNum: 1,
		pageSize: 20,
	})
	const queryList = (pageNo, pageSize) => {
		firstInfo.value = false
		queryParams.value.pageNum = pageNo
		getMyActiveApi(unref(queryParams)).then(res => {
			paging.value.complete(res.list)
		})
	}
	
	const onSearch = () => {
		queryParams.value.pageNum = 1
		paging.value.reload()
	}
	
	const onClean = () => {
		queryParams.value.activeTitle = ''
		queryParams.value.pageNum = 1
		dataList.value = []
		paging.value.reload()
	}
	
	const refresh = () => {
		console.log('页面刷新', paging.value)
		if (paging.value) {
			onSearch()
		}
	}
	onShow((options) => {
		// console.log('show',options,firstInfo.value)
		if(!firstInfo.value){
			refresh()
		}
	})
	onBackPress((options) =>{
		console.log(options,'onBackPress')
		refresh()
	})
	onMounted(() => {
	})
	onLoad((options) => {
		console.log('复制活动', options)
		from.value = options.from
	})
	defineExpose({
		refresh
	})
</script>

<style lang="scss" scoped>
</style>
